package com.ruoyi.teach.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.teach.domain.NbCourse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.teach.mapper.NbCourseAttributeMapper;
import com.ruoyi.teach.domain.NbCourseAttribute;
import com.ruoyi.teach.service.INbCourseAttributeService;

/**
 * 课程属性Service业务层处理
 * 
 * @author ruoyi
 * @date 2021-12-08
 */
@Service
public class NbCourseAttributeServiceImpl implements INbCourseAttributeService 
{
    @Autowired
    private NbCourseAttributeMapper nbCourseAttributeMapper;

    /**
     * 查询课程属性
     * 
     * @param id 课程属性主键
     * @return 课程属性
     */
    @Override
    public NbCourseAttribute selectNbCourseAttributeById(Long id)
    {
        return nbCourseAttributeMapper.selectNbCourseAttributeById(id);
    }

    /**
     * 查询课程属性列表
     * 
     * @param nbCourseAttribute 课程属性
     * @return 课程属性
     */
    @Override
    public List<NbCourseAttribute> selectNbCourseAttributeList(NbCourseAttribute nbCourseAttribute)
    {
        return nbCourseAttributeMapper.selectNbCourseAttributeList(nbCourseAttribute);
    }

    /**
     * 新增课程属性
     * 
     * @param nbCourseAttribute 课程属性
     * @return 结果
     */
    @Override
    public int insertNbCourseAttribute(NbCourseAttribute nbCourseAttribute)
    {
        nbCourseAttribute.setCreateTime(DateUtils.getNowDate());
        return nbCourseAttributeMapper.insertNbCourseAttribute(nbCourseAttribute);
    }

    /**
     * 修改课程属性
     * 
     * @param nbCourseAttribute 课程属性
     * @return 结果
     */
    @Override
    public int updateNbCourseAttribute(NbCourseAttribute nbCourseAttribute)
    {
        return nbCourseAttributeMapper.updateNbCourseAttribute(nbCourseAttribute);
    }

    /**
     * 批量删除课程属性
     * 
     * @param ids 需要删除的课程属性主键
     * @return 结果
     */
    @Override
    public int deleteNbCourseAttributeByIds(Long[] ids)
    {
        return nbCourseAttributeMapper.deleteNbCourseAttributeByIds(ids);
    }

    /**
     * 删除课程属性信息
     * 
     * @param id 课程属性主键
     * @return 结果
     */
    @Override
    public int deleteNbCourseAttributeById(Long id)
    {
        return nbCourseAttributeMapper.deleteNbCourseAttributeById(id);
    }

    /**
     * 通过课程id查询课程
     *
     * @param nbCourse 课程属性
     * @return  结果
     */
    @Override
    public List<NbCourseAttribute> selectNbCourseAttributeBycId(NbCourse nbCourse) {
        List<NbCourseAttribute> list = nbCourseAttributeMapper.selectNbCourseAttributeBycId(nbCourse);
        if(list.size()==0){
            NbCourseAttribute nbCourseAttribute = new NbCourseAttribute();
            Long cId = nbCourse.getId();
            nbCourseAttribute.setCourseId(cId);
            insertNbCourseAttribute(nbCourseAttribute);
            list = nbCourseAttributeMapper.selectNbCourseAttributeBycId(nbCourse);
        }
        return list;
    }
}
